package com.example.demo.mapper;

import com.example.demo.entity.Auth;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 三石
* @description  针对表【auth(系统菜单)】的数据库操作Mapper
* @createDate  2024-05-06 21:39:48
* @Entity  com.example.demo.domain.Auth
*/
@Mapper
public interface AuthMapper extends BaseMapper<Auth> {
    /**
     * 根据权限id集合，查询权限uri集合
     * @param authIds 权限id集合
     * @return uri集合
     */
    @Select("<script>"+
            "select uri from auth where id in "+
            "<foreach collection='authIds' item='item' open='(' close=')' separator=','>"+
            "#{item}" +
            "</foreach>" +
            "</script> ")
    List<String> selectUriByIds(@Param("authIds") List<Long> authIds);

    @Select("select id,pid,name,path ,redirect ,component,meta_title,meta_icon,is_hidden from auth where type in ('1','2')")
    List<Auth> selectMenuByUsername(@Param("username") String username);

    @Select(("<script>"+
            "SELECT id, pid, name, path, redirect, component, meta_title, meta_icon, is_hidden " +
            "FROM auth " +
            "WHERE type = 2 " +
            "AND id IN " +
            "<foreach collection='authIds' item='authId' open='(' close=')' separator=','>" +
            "#{authId}" +
            "</foreach>" +
            "</script> "))
    List<Auth> selectMenuByAuthIds(@Param("authIds") List<Long> authIds);

    @Select(("<script>"+
            "SELECT id, pid, type ,name, path, redirect, component, meta_title, meta_icon, is_hidden " +
            "FROM auth " +
            "WHERE (type = 0 OR (type = 1 AND pid != 0))" +
            "AND id IN " +
            "<foreach collection='authIds' item='authId' open='(' close=')' separator=','>" +
            "#{authId}" +
            "</foreach>" +
            "</script> "))
    List<Auth> selectTopMenuByAuthIds(@Param("authIds") List<Long> authIds);
}




